package KeTangLian;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo {
	public static void main(String[] args) { 
		try {
			//1 加载驱动
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("执行成功");
			//2 连接数据库
			Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/java十一章", "root", "123456");
			System.out.println("sql执行成功");
			//3 创建执行sql语句
			Statement statement=connection.createStatement();
			//Scanner scanner=new Scanner(System.in);
			//System.out.println("id");
			//int id=scanner.nextInt();
			//System.out.println("姓名");
			//String nameString=scanner.next();
			//System.out.println("性别");
			//String sexString=scanner.next();
			//String sqlString="SELECT id,name,sex FROM student";//查看
			//String sqlString="DELETE FROM student WHERE id='"+id+"';";//删除
			//String sqlString="UPDATE student SET name='"+nameString+"' WHERE id='"+id+"'";//修改
			//String sqlString="INSERT student VALUES('"+id+"','"+nameString+"','"+sexString+"')";//添加
			//String sqlString2="SELECT tid,Tname,Age FROM studentinfo1";//查看
			//String sqlString1="INSERT studentinfo1(tid,Tname,Age) VALUES(190202,'zl',20)";//添加
			//String sqlString="DELETE FROM studentinfo1 WHERE tid='190201';";//删除
			String sqlString="UPDATE studentinfo1 SET tname='1234' WHERE tid='190202'";//修改
			//4 对结果进行处理
			//ResultSet resultSet=statement.executeQuery(sqlString2);
			int result=statement.executeUpdate(sqlString);
			/*while (resultSet.next()) {
				System.out.println(resultSet.getInt("tid")+" "+
			resultSet.getString("Tname")+" "+resultSet.getInt("Age"));
				
			}*/
			if (result>0) {
				System.out.println("成功");
			}else {
				System.out.println("失败");
		    }
			//5 关闭
			//resultSet.close();
			statement.close();
			connection.close();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("执行失败");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("sql执行失败");
		}
	}
}
